<template>
  <div>
    <TopFilter ref="searchOrdersPanel" :labelWidth="120" :list="topFilterList" :cols="4" :rows="2" @filterChange="getinsuranceList" @onCollapse="collapseHandle"></TopFilter>
    <ButtonArea :style="{ paddingLeft: '0px' }">
      <el-button type="primary" icon="el-icon-refresh-left" @click="openRepairhistory">维修历史</el-button>
      <el-button type="primary" icon="el-icon-refresh-left" @click="openRepairImport">维修建议</el-button>
      <el-button type="primary" icon="el-icon-refresh-left" @click="openComplaint">投诉历史</el-button>
      <el-button type="primary" icon="el-icon-refresh-left" :loading="exportLoading" @click="remindExport">导出</el-button>
    </ButtonArea>
    <FilterTable
      ref="table"
      :fetchapi="fetchApi"
      :columns="columns"
      :params="fetchParams"
      :datakey="'rows'"
      :onRowSelectChange="arr => (this.onSelectCell = arr)"
      :onColumnsChange="columns => (this.columns = columns)"
    ></FilterTable>

    <ButtonArea :style="{ paddingLeft: '0px', textAlign: 'center' }">
      <el-button type="primary" @click="openPrecontract">预约安排</el-button>
      <!-- <el-button @click="openRemindInputs" type="primary">提醒录入</el-button> -->
      <!-- <el-button @click="openRemindHistory" type="primary">提醒历史</el-button>-->
      <el-button type="primary" icon="el-icon-refresh-left" @click="historyInsurance">历史保单</el-button>
      <!-- <el-button type="primary" icon="el-icon-delete" @click="showImportFun">Excel更新到日期月日</el-button> -->
    </ButtonArea>

    <div>
      <span>被选项全部分配给 跟踪员</span>
      <el-select v-model="value" placeholder="请选择" @change="traceChange">
        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
      </el-select>
      <el-button icon="el-icon-document" @click="traceRemindAssign">分派</el-button>
    </div>

    <BaseDialog :visible.sync="showHistory" title="保险历史信息" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <historyQuery :VIN="VIN" @close="closeHistory" />
    </BaseDialog>

    <Drawer :visible.sync="showRepairhistory" title="维修历史" width="1300" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <Repairhistory ref="Repairhistory" :getdata="onSelectCell[0]" @close="closeRepairhistory" />
    </Drawer>

    <Drawer :visible.sync="showRepairImport" title="维修建议" width="1300" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <!-- <RepairImport ref="RepairImport" :vin="chooseVin" @cancel="closeRepairImport" /> -->
    </Drawer>

    <Drawer :visible.sync="showComplaint" title="投诉历史" width="1300" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <Complaint ref="Complaint" :vin="chooseVin" @close="closeComplaint" />
    </Drawer>

    <Drawer :visible.sync="showReservation" title="预约安排" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <Precontract ref="Precontract" :Vin="chooseVin" :License="chooseLicense" @close="closePrecontract" />
    </Drawer>

    <Drawer :visible.sync="showRemindInputs" title="提醒录入" width="1300" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <RemindInputs ref="RemindInputs" :remindData="selectData" @close="closeRemindInputs" />
    </Drawer>

    <Drawer :visible.sync="showRemindHistory" title="提醒历史" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <RemindHistory :vin="chooseVin" :ownerNo="chooseOwnerNo" :remindSource="3" @close="closeRemindHistory" />
      <div
        :style="{
          position: 'absolute',
          left: 0,
          bottom: 0,
          right: 0,
          zIndex: 9999,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'right'
        }"
      >
        <el-button @click="closeRemindHistory">返 回</el-button>
      </div>
    </Drawer>

    <BaseDialog :visible.sync="showImport" title="导入" width="800px" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <importRemind />
    </BaseDialog>
    <BaseDialog title="选择单" :visible.sync="workSearchDialog" destroyOnClose>
      <serviceAct :workNo="WorkSearch_rono" @close1="closeActivity" @ReceiveData="ReceiveData"></serviceAct>
    </BaseDialog>
  </div>
</template>

<script>
import serviceAct from './serviceAct';
import { getPinpSelect, getChexSelect, getCheModelSelect } from '@/api/repair/repairReception/customer';
import {
  getBrand,
  getSeries,
  getModel,
  getRegion,
  getExcelList,
  remindAssign,
  getMaintainAdvisor,
  getDcrcAdvisor,
  getInsuranceAdvisor
} from '@/api/customerRepair/customerCare/insuranceDueRemind/index';
import { getProvince, getCitys } from '@/api/customerRepair/customerInfo/ownerVehicleManagement/index';
import { getinsuranceList } from '@/api/customerRepair/customerLoss/lossRemind';
import { dictionary } from '@/utils/dictMixin';
import { jsonToHump } from '@/utils/index';
import historyQuery from './historyQuery.vue';
import importRemind from './importRemind.vue';
import RemindHistory from '@/pages/customerRepair/customerLoss/lossRemind/remindHistory.vue';
import RemindInputs from '@/pages/customerRepair/customerCare/maintenanceRemind/remindInputs.vue';
// 查询定保专员
import { searchRoleByCode } from '@/api/common/empSelect/index';
import dictCode from '@/utils/dictCode';
import Repairhistory from '@/pages/repair/business/customer/Repairhistory/historypop.vue'; // 维修历史
// import RepairImport from '@/pages/repair/repairReception/customer/repairImport/Modal.vue'; // 维修建议
import Complaint from '@/pages/repair/business/customer/combination/complaint'; // 投诉历史
import Precontract from '@/pages/repair/repairReception/precontractArrange'; // 预约安排
import { exportExcelFile } from '@/utils/index';
import { getDealerUser } from '@/api/part/partInventory/partInventory/index.js';
import { getSystemDefault } from '@/api/repair/repairReception/customer';
export default {
  name: 'zjCustomerRepair',
  components: {
    historyQuery,
    Repairhistory,
    importRemind,
    RemindHistory,
    RemindInputs,
    // RepairImport,
    Complaint,
    Precontract,
    serviceAct
  },
  mixins: [dictionary],
  data() {
    return {
      WorkSearch_rono: '', // 搜索参数
      workSearchDialog: false, // 搜索弹窗
      topFilterList: this.createTop(),
      fetchApi: getinsuranceList,
      columns: this.createTable(),
      onSelectCell: [],
      fetchParams: { xhrAbort: true },
      showRemindInputs: false,
      showRemindHistory: false,
      // 预约安排
      showReservation: false,
      showHistory: false,
      historyVisible: false,
      showImport: false,
      chooseVin: null,
      chooseOwnerNo: null,
      chooseLicense: null,
      selectData: null,
      selectedRows: [],
      VIN: '',
      options: [],
      value: '',
      trace: '', // 跟踪人
      traceObj: {},
      vins: '', // vin号
      licenses: '', // 车牌号
      ownerNos: '', // 车主编号
      exportLoading: false,
      showComplaint: false, // 投诉历史
      showRepairhistory: false, // 维修历史
      showRepairImport: false, // 维修建议
      days: '' // 获取参数
    };
  },
  mounted() {
    this.queryDefaultPa();
    this.getMaintainAdvisor();
    this.serviceConsultant();
    this.getDealerUser();
    this.queryRegion();
    this.getTraceList();
    this.queryBrand();
    this.querySeries();
    this.queryModel();
  },
  methods: {
    // 获取下次保养日期：当天~当天+定保到期提前X天
    async queryDefaultPa() {
      let params = { itemCode: 6001 };
      let res = await getSystemDefault(params);
      this.days = res.data; // 获取天数
      this.topFilterList.find(item => item.fieldName === 'nextMaintainFromDate|nextMaintainToDate').initialValue = [
        moment(new Date()).format('YYYY-MM-DD'),
        moment(new Date())
          .add(this.days, 'day')
          .format('YYYY-MM-DD')
      ];
      // 初始化查询条件数值未进场天数360,390
      this.topFilterList.find(item => item.fieldName === 'daysFrom').initialValue = 360;
      this.topFilterList.find(item => item.fieldName === 'daysTo').initialValue = 390;
    },
    createTop() {
      let that = this;
      return [
        {
          type: 'SELECT',
          label: '品牌',
          fieldName: 'brandName',
          itemList: []
        },
        {
          type: 'INPUT',
          label: '车主',
          fieldName: 'ownerName'
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'license'
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin'
        },
        {
          type: 'RANGE_DATE',
          label: '下次保养日期',
          fieldName: 'nextMaintainFromDate|nextMaintainToDate',
          valueFormat: 'yyyy-MM-dd'
        },
        {
          type: 'RANGE_DATE',
          label: '上次维修日期',
          fieldName: 'lastMaintainFromDate|lastMaintainToDate',
          valueFormat: 'yyyy-MM-dd'
        },
        {
          type: 'RANGE_DATE',
          label: '首次进厂日期',
          fieldName: 'firstInDateFrom|firstInDateTo',
          valueFormat: 'yyyy-MM-dd'
        },
        {
          type: 'RANGE_DATE',
          label: '销售日期',
          fieldName: 'salesDateFrom|salesDateTo',
          valueFormat: 'yyyy-MM-dd'
        },
        {
          type: 'INPUT_NUMBER',
          label: '未进场天数',
          hidden: false,
          fieldName: 'daysFrom'
        },
        {
          type: 'INPUT_NUMBER',
          label: '至',
          hidden: false,
          fieldName: 'daysTo'
        },
        {
          type: 'INPUT',
          label: '保险到期年',
          hidden: true,
          fieldName: 'expiredYear'
        },
        {
          type: 'INPUT_NUMBER',
          label: '保险到期月',
          hidden: false,
          min: 1,
          max: 12,
          fieldName: 'expiredMonth'
        },
        {
          type: 'INPUT_NUMBER',
          label: '保险到期日',
          hidden: false,
          min: 1,
          max: 31,
          fieldName: 'expiredDay'
        },
        {
          type: 'RANGE_DATE',
          label: '最近提醒日期',
          fieldName: 'remindDateFrom|remindDateTo',
          valueFormat: 'yyyy-MM-dd',
          change: this.remindChange
        },
        {
          type: 'INPUT',
          label: '服务活动',
          fieldName: 'ACTIVITY_CODE',
          placeholder: '请输入服务活动',
          hidden: true,
          initialValue: '',
          unitRender: () => {
            return <el-button icon="el-icon-search" onClick={this.gdClickHandle}></el-button>;
          },
          onEnter: val => {
            this.WorkSearch_rono = val;
            this.gdClickHandle();
          },
          placeholder: '请输入...'
        },
        {
          type: 'CHECKBOX',
          label: '排除已参与活动车辆',
          hidden: true,
          fieldName: 'joinAct'
        },
        {
          type: 'SELECT',
          label: '提醒状态',
          fieldName: 'remindStatus',
          itemList: this.createDictList('8057')
        },
        {
          type: 'SELECT',
          label: '是否提醒回厂',
          fieldName: 'isReturnFactory',
          itemList: this.createDictList('1004'),
          disabled: true
        },
        {
          type: 'INPUT',
          label: '监控信息',
          hidden: true,
          fieldName: 'monitorInfo'
        },
        {
          type: 'SELECT',
          label: '是否激活',
          fieldName: 'isValid',
          itemList: this.createDictList('1004')
        },
        {
          type: 'SELECT',
          label: '提醒方式',
          fieldName: 'remindWay',
          itemList: this.createDictList('8081')
        },
        {
          type: 'SELECT',
          label: '上次接待服务顾问',
          fieldName: 'lastConsultantId',
          filterable: true,
          itemList: []
        },
        {
          type: 'SELECT',
          label: '定保专员',
          fieldName: 'maintainAdvisor',
          filterable: true,
          itemList: []
        },
        {
          type: 'SELECT',
          label: '客服专员',
          fieldName: 'serviceAdvisor',
          filterable: true,
          itemList: []
        },
        {
          type: 'SELECT',
          label: '保险专员',
          fieldName: 'insuranceAdvisor',
          filterable: true,
          itemList: []
        }
      ];
    },

    createTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        // {
        //   title: '操作',
        //   dataIndex: 'column-action',
        //   width: 50,
        //   fixed: 'left',
        //   // render: props => {
        //   //   return (
        //   //     <div>
        //   //       <el-button size="mini" type="text">
        //   //         操作
        //   //       </el-button>
        //   //     </div>
        //   //   );
        //   // }
        // },
        // {
        //   title: '经销商',
        //   dataIndex: 'DEALER_SHORTNAME',
        //   sorter: true,
        // },
        {
          title: '险种',
          dataIndex: 'INSURANCE_TYPE_NAME',
          sorter: true,
          hidden: true
        },
        {
          title: '车牌号',
          dataIndex: 'LICENSE',
          sorter: true
        },
        {
          title: 'VIN',
          dataIndex: 'VIN',
          width: 150,
          sorter: true
        },
        {
          title: '品牌',
          dataIndex: 'BRAND',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: false,
          editType: 'select',
          editItems: []
        },
        {
          title: '车系',
          dataIndex: 'SERIES',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: false,
          editType: 'select',
          editItems: []
        },
        {
          title: '车型',
          dataIndex: 'MODEL',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: false,
          editType: 'select',
          editItems: []
        },
        {
          title: '车主编号',
          dataIndex: 'OWNER_NO',
          sorter: true
        },
        {
          title: '车主',
          dataIndex: 'OWNER_NAME',
          sorter: true
        },
        {
          title: '车主电话',
          dataIndex: 'PHONE',
          sorter: true
        },
        {
          title: '车主手机',
          dataIndex: 'MOBILE',
          sorter: true
        },
        {
          title: '车主地址',
          dataIndex: 'ADDRESS',
          sorter: true
        },
        {
          title: '车主性质',
          dataIndex: 'OWNER_PROPERTY',
          sorter: true,
          render: props => {
            return <span>{props.row.OWNER_PROPERTY ? this.createDictText(props.row.OWNER_PROPERTY, '8011') : ''}</span>;
          }
        },
        {
          title: '送修人',
          dataIndex: 'DELIVERER',
          sorter: true
        },
        {
          title: '送修人手机',
          dataIndex: 'DELIVERER_MOBILE',
          sorter: true
        },
        {
          title: '送修人电话',
          dataIndex: 'DELIVERER_PHONE',
          sorter: true
        },
        {
          title: '联系人',
          dataIndex: 'CONTACTOR_NAME',
          sorter: true
        },
        {
          title: '联系人手机',
          dataIndex: 'CONTACTOR_MOBILE',
          sorter: true
        },
        {
          title: '联系人电话',
          dataIndex: 'CONTACTOR_PHONE',
          sorter: true
        },
        {
          title: '联系人邮编',
          dataIndex: 'CONTACTOR_ZIP_CODE',
          sorter: true
        },
        {
          title: '联系人详细地址',
          dataIndex: 'CONTACTOR_ADDRESS',
          sorter: true
        },
        {
          title: '保险公司',
          dataIndex: 'INSURATION_NAME',
          sorter: true,
          hidden: false
        },
        {
          title: '保险开始日期',
          dataIndex: 'INSURANCE_BEGIN_DATE',
          hidden: true,
          sorter: true,
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '保险结束日期',
          dataIndex: 'INSURANCE_END_DATE',
          hidden: true,
          sorter: true,
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '上次维修日期',
          dataIndex: 'LAST_MAINTAIN_DATE',
          sorter: true,
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '上次维修里程',
          dataIndex: 'LAST_MAINTAIN_MILEAGE',
          sorter: true
        },
        {
          title: '预计下次保养日期',
          dataIndex: 'NEXT_MAINTAIN_DATE',
          sorter: true,
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '下次保养里程',
          dataIndex: 'NEXT_MAINTAIN_MILEAGE',
          sorter: true
        },
        {
          title: '服务顾问',
          dataIndex: 'SERVICE_NAME',
          sorter: true,
          disabled: true,
          editable: true,
          editType: 'select',
          editItems: []
        },
        {
          title: '提醒人',
          dataIndex: 'REMINDER',
          sorter: true,
          disabled: true,
          editable: true,
          editType: 'select',
          editItems: []
        },
        {
          title: '提醒内容',
          dataIndex: 'REMIND_CONTENT',
          sorter: true
        },
        {
          title: '提醒状态',
          dataIndex: 'REMIND_STATUS',
          sorter: true,
          render: props => {
            return <span>{props.row.REMIND_STATUS ? this.createDictText(props.row.REMIND_STATUS, '8057') : ''}</span>;
          }
        },
        {
          title: '提醒失败原因',
          dataIndex: 'REMIND_FAIL_REASON',
          sorter: true,
          render: props => {
            return <span>{props.row.REMIND_FAIL_REASON ? this.createDictText(props.row.REMIND_FAIL_REASON, '8069') : ''}</span>;
          }
        },
        {
          title: '最后一次提醒时间',
          dataIndex: 'REMIND_DATE',
          sorter: true,
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '客户反馈',
          dataIndex: 'CUSTOMER_FEEDBACK',
          sorter: true
        },
        {
          title: '销售日期',
          dataIndex: 'SALES_DATE',
          sorter: true,
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '是否激活',
          dataIndex: 'IS_VALID',
          sorter: true,
          render: props => {
            return <span>{props.row.IS_VALID ? this.createDictText(props.row.IS_VALID, '1004') : ''}</span>;
          }
        },
        {
          title: '优惠截止日期',
          dataIndex: 'DISCOUNT_EXPIRE_DATE',
          sorter: true,
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '定保专员',
          dataIndex: 'MAINTAIN_ADVISOR',
          sorter: true,
          disabled: true,
          editable: true,
          editType: 'select',
          editItems: []
        },
        {
          title: '上次保养日期',
          dataIndex: 'LAST_MAINTENANCE_DATE',
          sorter: true,
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '上次保养里程',
          dataIndex: 'LAST_MAINTENANCE_MILEAGE',
          sorter: true
        },
        {
          title: '提醒方式',
          dataIndex: 'REMIND_WAY',
          sorter: true,
          render: props => {
            return <span>{props.row.REMIND_WAY ? this.createDictText(props.row.REMIND_WAY, '8081') : ''}</span>;
          }
        },
        {
          title: '最近两次提醒时间',
          dataIndex: '14',
          hidden: true,
          sorter: true,
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '最近三次提醒时间',
          dataIndex: '15',
          hidden: true,
          sorter: true,
          dateFormat: 'yyyy-MM-dd'
        },
        // {
        //   title: '上次维修时间',
        //   dataIndex: '16', // LAST_MAINTAIN_DATE16
        //   sorter: true,
        //   dateFormat: 'yyyy-MM-dd'
        // },
        {
          title: '是否本公司投保',
          dataIndex: 'IS_SELF_COMPANY_INSURANCE',
          sorter: true,
          render: props => {
            return <span>{props.row.IS_SELF_COMPANY_INSURANCE ? this.createDictText(props.row.IS_SELF_COMPANY_INSURANCE, '1004') : ''}</span>;
          }
        },
        {
          title: '续保专员',
          dataIndex: 'INSURANCE_NAME',
          sorter: true,
          disabled: true,
          editable: true,
          editType: 'select',
          editItems: []
        },
        {
          title: '是否提醒回厂',
          dataIndex: 'IS_RETURN_FACTORY',
          sorter: true,
          render: props => {
            return <span>{props.row.IS_RETURN_FACTORY ? this.createDictText(props.row.IS_RETURN_FACTORY, '1004') : ''}</span>;
          }
        },
        {
          title: '保险到期年',
          dataIndex: 'EXPIRED_YEAR',
          sorter: true,
          hidden: true
        },
        {
          title: '保险到期月',
          dataIndex: 'EXPIRED_MONTH',
          sorter: true,
          hidden: false
        },
        {
          title: '保险到期日',
          dataIndex: 'EXPIRED_DAY',
          sorter: true,
          hidden: false
        },
        {
          title: '保险备注1',
          dataIndex: 'REMARK1',
          sorter: true,
          hidden: true
        },
        {
          title: '保险备注2',
          dataIndex: 'REMARK2',
          sorter: true,
          hidden: true
        },
        {
          title: '购买意向',
          dataIndex: 'PUR_INTENTION',
          sorter: true,
          hidden: true,
          render: props => {
            return <span>{this.createDictText(props.row.PUR_INTENTION, '8083')}</span>;
          }
        },
        {
          title: '需求卖点',
          dataIndex: 'SELLING_POINT',
          sorter: true
        },
        {
          title: '意向保险公司',
          dataIndex: 'PUR_COMPANY',
          sorter: true,
          hidden: true
        },
        {
          title: '车身状态',
          dataIndex: 'BODY_STATE',
          sorter: true
        },
        // {
        //   title: '是否本公司购车',
        //   dataIndex: 'IS_SELF_COMPANY',
        //   sorter: true,
        //   render: props => {
        //     return <span>{props.row.IS_SELF_COMPANY ? this.createDictText(props.row.IS_SELF_COMPANY, '1004') : ''}</span>;
        //   }
        // },
        {
          title: '行驶里程',
          dataIndex: 'MILEAGE',
          sorter: true
        },
        {
          title: '第一次进厂日期',
          dataIndex: 'FIRST_IN_DATE',
          sorter: true,
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '跟踪状态',
          dataIndex: 'TRACE_TYPE',
          sorter: true,
          render: props => {
            return <span>{props.row.TRACE_TYPE ? this.createDictText(props.row.TRACE_TYPE, '8058') : ''}</span>;
          }
        },
        {
          title: '性别',
          dataIndex: 'GENDER',
          sorter: true,
          render: props => {
            return <span>{props.row.GENDER ? this.createDictText(props.row.GENDER, '8012') : ''}</span>;
          }
        },
        {
          title: '出生日期',
          dataIndex: 'BIRTHDAY',
          sorter: true,
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '车主邮编',
          dataIndex: 'ZIP_CODE',
          sorter: true
        },
        // {
        //   title: '销售顾问',
        //   dataIndex: 'CONSULTANT',
        //   sorter: true,
        //   disabled: true,
        //   editable: true,
        //   editType: 'select',
        //   editItems: []
        // },
        {
          title: '省份',
          dataIndex: 'PROVINCE',
          sorter: true,
          disabled: true,
          editable: true,
          editType: 'select',
          editItems: []
        },
        {
          title: '城市',
          dataIndex: 'CITY',
          sorter: true,
          disabled: true,
          editable: true,
          editType: 'select',
          editItems: []
        },
        {
          title: '流失时间',
          dataIndex: 'LOSS_DATE',
          sorter: true
        }
      ];
    },
    // 最近提醒日期变更时间
    remindChange(val) {
      if (val[0] !== undefined && val[1] !== undefined && val[1] !== '' && val[0] !== '') {
        // 获取回厂提醒点亮
        this.topFilterList.find(item => item.fieldName === 'isReturnFactory').disabled = false;
      } else {
        // 获取回厂提醒为空 且置灰
        this.topFilterList.find(item => item.fieldName === 'isReturnFactory').initialValue = undefined;
        this.topFilterList.find(item => item.fieldName === 'isReturnFactory').disabled = true;
      }
    },
    // 服务活动弹框
    gdClickHandle() {
      this.workSearchDialog = true;
    },
    // 接收服务活动确定返回
    ReceiveData(val) {
      this.topFilterList.find(x => x.fieldName === 'ACTIVITY_CODE').initialValue = val.ACTIVITY_CODE;
      this.workSearchDialog = false;
    },
    closeActivity(val) {
      this.workSearchDialog = false;
    },
    // 获取提醒人
    async getDealerUser() {
      const res = await getDealerUser();
      // 定保专员
      this.columns.find(x => x.dataIndex === 'MAINTAIN_ADVISOR').editItems = res.data.map(x => ({ value: x.userId.toString(), text: x.employeeName }));
      // 续保专员
      this.columns.find(x => x.dataIndex === 'INSURANCE_NAME').editItems = res.data.map(x => ({ value: x.userId.toString(), text: x.employeeName }));
      // 提醒人
      this.columns.find(x => x.dataIndex === 'REMINDER').editItems = res.data.map(x => ({ value: x.userId.toString(), text: x.employeeName }));
      // 服务顾问
      this.columns.find(x => x.dataIndex === 'SERVICE_NAME').editItems = res.data.map(x => ({ value: x.userId, text: x.employeeName }));
      // 销售顾问
      // this.columns.find(x => x.dataIndex === 'CONSULTANT').editItems = res.data.map(x => ({ value: x.userId.toString(), text: x.employeeName }));
    },
    // 查询省市(供table使用)
    async queryRegion() {
      const res = await getRegion();
      let list = res.data.map(x => ({ text: x.REGION_NAME, value: x.REGION_ID }));
      this.columns.find(x => x.dataIndex === 'PROVINCE').editItems = list;
      this.columns.find(x => x.dataIndex === 'CITY').editItems = list;
    },

    // 查询所有品牌(供table使用)
    async queryBrand() {
      const res = await getBrand();
      this.columns.find(x => x.dataIndex === 'BRAND').editItems = res.data.map(x => ({ text: x.BRAND_NAME, value: x.BRAND_ID + '' }));
      this.topFilterList.find(item => item.fieldName === 'brandName').itemList = res.data.map(x => ({ value: x.BRAND_ID, text: x.BRAND_NAME })); //
    },
    // 查询所有车系(供table使用)
    async querySeries() {
      const res = await getSeries();
      this.columns.find(x => x.dataIndex === 'SERIES').editItems = res.data.map(x => ({ text: x.SERIES_NAME, value: x.SERIES_ID + '' }));
    },
    // 查询所有车型(供table使用)
    async queryModel() {
      const res = await getModel();
      this.columns.find(x => x.dataIndex === 'MODEL').editItems = res.data.map(x => ({ text: x.MODEL_NAME, value: x.MODEL_ID + '' }));
    },
    async serviceConsultant() {
      let roleParam = { role: dictCode.SERVICE_CONSULTANT };
      const res = await searchRoleByCode(roleParam);
      this.topFilterList.find(item => item.fieldName === 'lastConsultantId').itemList = res.data.map(x => ({ text: x.employeeName, value: x.userId }));
    },
    async getMaintainAdvisor() {
      // 客服专员
      const res2 = await getDcrcAdvisor();
      this.topFilterList.find(item => item.fieldName === 'serviceAdvisor').itemList = res2.data.map(x => ({ text: x.employeeName, value: x.userId }));
      // 保险专员
      const res1 = await getInsuranceAdvisor();
      this.topFilterList.find(item => item.fieldName === 'insuranceAdvisor').itemList = res1.data.map(x => ({ text: x.employeeName, value: x.userId }));
      // 定保专员
      const res = await getMaintainAdvisor();
      this.topFilterList.find(item => item.fieldName === 'maintainAdvisor').itemList = res.data.map(x => ({ text: x.employeeName, value: x.userId }));
    },
    // 获取分派的option数据
    async getTraceList() {
      let roleParam = { role: dictCode.SERVICE_CONSULTANT };
      const res = await searchRoleByCode(roleParam);
      // console.log(res, '服务顾问');
      this.options = res.data.map(x => ({ label: x.employeeName, value: x.userId }));
    },

    // 分派员下拉框改变
    traceChange(val) {
      this.trace = val;
    },

    // 分派
    traceRemindAssign() {
      if (this.onSelectCell.length === 0) {
        this.$notify.error({ title: '提示信息', message: '请选择一条数据！' });
        return;
      }
      // vins vin号 licenses 车牌号 ownerNos 车主编号 trace 跟踪人
      let vins = '';
      let licenses = '';
      let ownerNos = '';
      for (let i = 0; i < this.onSelectCell.length; i++) {
        if (i === 0) {
          vins += this.onSelectCell[i].VIN;
          licenses += this.onSelectCell[i].LICENSE;
          ownerNos += this.onSelectCell[i].OWNER_NO;
        } else {
          vins = vins + ',' + this.onSelectCell[i].VIN;
          licenses = licenses + ',' + this.onSelectCell[i].LICENSE;
          ownerNos = ownerNos + ',' + this.onSelectCell[i].OWNER_NO;
        }
      }
      this.traceObj = {
        vins,
        licenses,
        ownerNos,
        trace: this.trace
      };
      console.log(this.traceObj, 'traceObj');
      // debugger;
      this.$confirm('是否确认分派?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          const res = await remindAssign(this.traceObj);
          if (res.resultCode == 200) {
            this.traceObj = {};
            this.$message({
              type: 'success',
              message: '分配成功!'
            });
          }
        })
        .catch(() => {});
    },

    selectChange(row) {
      console.log(row, 'row');
      this.selectedRows = row;
    },
    changeHandle(val) {},
    getinsuranceList(val) {
      this.fetchParams = Object.assign({}, val, { xhrAbort: false });
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.$refs.table.$refs.pageTable.EXECUTE_RESET_HEIGHT();
      });
    },
    query() {
      this.$refs.searchOrdersPanel.SUBMIT_FORM();
    },

    // 维修历史
    openRepairhistory(data) {
      if (this.onSelectCell.length == 1) {
        this.saveData(this.onSelectCell);
        this.showRepairhistory = true;
      } else {
        this.$notify.error({ title: '提示信息', message: '请选择一条表格数据！' });
      }
    },
    closeRepairhistory(data) {
      this.showRepairhistory = false;
    },

    saveData(val) {
      this.chooseVin = val[0].VIN;
      this.chooseLicense = val[0].LICENSE;
      this.chooseOwnerNo = val[0].OWNER_NO;
    },

    // 维修建议
    openRepairImport(data) {
      if (this.onSelectCell.length == 1) {
        this.saveData(this.onSelectCell);
        this.showRepairImport = true;
      } else {
        this.$notify.error({ title: '提示信息', message: '请选择一条表格数据！' });
      }
    },
    closeRepairImport(data) {
      this.showRepairImport = false;
    },
    // 投诉历史
    openComplaint(data) {
      if (this.onSelectCell.length == 1) {
        this.saveData(this.onSelectCell);
        this.showComplaint = true;
      } else {
        this.$notify.error({ title: '提示信息', message: '请选择一条表格数据！' });
      }
    },
    closeComplaint(data) {
      this.showComplaint = false;
    },

    // 导出
    remindExport() {
      this.exportLoading = true;
      getExcelList(this.fetchParams).then(res => {
        exportExcelFile(res, '客户流失提醒');
        this.exportLoading = false;
      });
    },

    // 预约安排
    openPrecontract(data) {
      if (this.onSelectCell.length == 1) {
        this.saveData(this.onSelectCell);
        this.showReservation = true;
      } else {
        this.$notify.error({ title: '提示信息', message: '请选择一条表格数据！' });
      }
    },
    closePrecontract(data) {
      this.showReservation = false;
    },

    openRemindInputs(data) {
      if (this.onSelectCell.length == 1) {
        this.selectData = _.cloneDeep(this.onSelectCell[0]);
        jsonToHump(this.selectData);
        // console.log(this.selectData)
        this.showRemindInputs = true;
      } else {
        this.$notify.error({ title: '提示信息', message: '请选择一条表格数据！' });
      }
    },
    closeRemindInputs(data) {
      this.showRemindInputs = false;
    },
    historyInsurance(val) {
      if (this.onSelectCell.length == 1) {
        this.VIN = this.onSelectCell[0].VIN;
        this.showHistory = true;
      } else {
        this.$notify.error({ title: '提示信息', message: '请选择一条表格数据！' });
      }
    },

    openRemindHistory(data) {
      if (this.onSelectCell.length == 1) {
        this.chooseVin = this.onSelectCell[0].VIN;
        this.chooseOwnerNo = this.onSelectCell[0].OWNER_NO;
        this.showRemindHistory = true;
      } else {
        this.$notify.error({ title: '提示信息', message: '请选择一条表格数据！' });
      }
    },
    closeRemindHistory(data) {
      this.showRemindHistory = false;
    },
    closeHistory() {
      this.showHistory = false;
    },
    showImportFun() {
      this.showImport = true;
    }
  }
};
</script>

<style scoped lang="less"></style>
